package com.iqiyi.pps.epg.core.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iqiyi.kiwi.utils.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lemuel on 2016/11/16.
 */
public class ApiBossUtil {

    private static Logger logger = LoggerFactory.getLogger(ApiBossUtil.class);

    private ApiBossUtil() {
    }

    public static final String CHANNEL_CHARGE_URL = Configuration.getString("channel.charge.url");
    public static final String CHARGE_PAID = "1";
    public static final String CHARGE_PAID_OLD = "2";
    public static final String CHARGE_FREE = "0";


    public static boolean channelCharge(Long id, Long qipuId, String name, long startTime, long endTime, int vipType) {
        boolean ret = false;
        Map<String, String> params = new HashMap<String, String>();
        params.put("qpid", qipuId.toString());
        params.put("makePrice", "1");
        params.put("charge", CHARGE_PAID);
        params.put("name", name);
        params.put("liveStartTime", "" + startTime);
        params.put("liveEndTime", "" + endTime);
        params.put("type", "1");
        params.put("vipContentType", "" + vipType);

        JSONObject result = ApiHttpRequestUtil.doPost(CHANNEL_CHARGE_URL, null, params);
        if (result != null && Constants.CODE_SUC.equals(result.getString("code"))) {
            ret = true;
        }
        if (qipuId.toString().endsWith("23")) {
            WriteSystemLogUtil.getInstance().writeProgramLog(id, Constants.LogType.NOTIFY_BOSS.getIndex(), "[url: " + CHANNEL_CHARGE_URL +"][params: " + JSON.toJSONString(params) + "][response: " + result.toJSONString() + "]");
        }
        return ret;
    }

}
